from __future__ import with_statement
from lib.classloader import register
from lib.pocbase import  pocbase


success = True;
try:
    import cx_Oracle
except:
    success = False;




class testpoc(pocbase):
    
    def __init__(self):        
        super(pocbase, self).__init__();
    
    def _match(self, infodict):
        port = infodict["port"];
        service_type = infodict["service_type"] if infodict.get("service_type") else "";
        version = infodict["service_version"] if infodict.get("service_version") else "";
        
        return int(port) == 3306 or version.lower().find("mysql") != -1 or service_type.lower().find("mysql") != -1;

    def _verify(self, infodict):
        host = infodict["ip"];
        port = infodict["port"];
        result = infodict;

        result["success"] = False;
        with open("data/mysql-username.txt") as username:
            with open("data/mysql-password.txt") as password:
                usernames = username.readlines()
                passwords = password.readlines();
                for u in usernames:
                    for p in passwords:
                        u = u.strip()
                        p = p.strip();
                        u = u.replace("\r", "")
                        u = u.replace("\n", "")
                        p = p.replace("\r", "")
                        p = p.replace("\n", "")
                        try:
                            #cx_Oracle.connect('hr', 'hrpwd', 'localhost:1521/XE')
                            break;
                        except:
                            pass
        return result;

if success:
    register(__file__, testpoc)
else:
    from lib.log import logToScreen
    logToScreen("critical", "to use oracle brute install ox_Oracle from http://cx-oracle.sourceforge.net/")
